<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>购物车示例</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<dev id="app" v-cloak>
    <template v-if="list.length">
        <table>
            <thead>
            <tr>
                <th></th>
                <th>商品名称</th>
                <th>商品单价</th>
                <th>购买数量</th>
                <th>操作</th>
                <th>选中</th>
            </tr>
            </thead>
            <tbody>
            <template v-for="(item1,index1) in list">
                <tr v-for="(item2,index2) in item1.child">
                    <td v-if="index2===0" :rowspan="item1.child.length">{{index1 + 1}}</td>
                    <td>{{item2.name}}</td>
                    <td>{{item2.price}}</td>
                    <td>
                        <button @click="handleReduce(index1,index2)"
                                :disabled="item2.count===1">-
                        </button>
                        {{item2.count}}
                        <button @click="handleAdd(index1,index2)">+</button>
                    </td>
                    <td>
                        <button @click="handleRemove(index1,index2)">移除</button>
                    </td>
                    <td>
                        <input type="checkbox" :checked="item2.checked" @click="checkboxOnClick(index1,index2)">
                    </td>
                </tr>
            </template>
            </tbody>
        </table>
        <div>总价：￥{{totalPrice}}
            <button @click="selectAll">全选</button>
        </div>
    </template>
    <div v-else>购物车为空</div>
</dev>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="index2.js"></script>
</body>
</html>
